//https://leetcode.cn/problems/longest-consecutive-sequence/submissions/581943712/
class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        int n = nums.size();
        if (n == 0)return 0;
        sort(&nums[0], &nums[n], [](const int& p1, const int& p2) {
            return p1 < p2;
            });
        unordered_map<int, int> hash;
        int ret = 0;
        for (int i = 0; i < n; ++i)
        {
            hash[nums[i]] = hash[nums[i] - 1] + 1;
            if (ret < hash[nums[i]])ret = hash[nums[i]];
        }
        return ret;
    }
};